<template>
    <el-container>
        <el-header style="height: 50px;border-bottom: none">
            <div class="left-panel">
                <el-button type="danger" plain icon="el-icon-delete" :disabled="selection.length == 0" @click="batch_del" v-auth="'summary.delete'" ></el-button>
                <sc-import-button :auth="'summary.import'" :apiObj="importObj" :base="base + '/file_templets/temples_inspect.xlsx'" @importSuccess="importSuccess" ></sc-import-button>
				<sc-export-button :auth="'summary.export'" :apiObj="apiObj" :search="search" :selection="selection"></sc-export-button>
                <div class="finish">
                    <div class="finishNum">米数:<div class="text">{{ total_stock.meter_sum }}</div></div>
                    <div class="finishNum">匹数:<div class="text">{{ total_stock.count }}</div></div>
                    <div class="finishNum">码数:<div class="text">{{ total_stock.code_number_sum }}</div></div>
                    <!-- <div class="finishNum">毛重:<div class="text">{{ total_stock.money }}</div></div> -->
                    <div class="finishNum">净重:<div class="text">{{ total_stock.net_weight_sum }}</div></div>
                </div>
            </div>
            <div class="right-panel">
                <div class="right-panel-search">
                    <sc-auto-complete style="margin:5px;width: 180px" v-model="search.apply_name" :api="$API.basic.apply.list" :params-key="'keyword'" :rows-key="'rows'" :value-key="'apply_name'" placeholder="供应商" @select="getApply"/>
                    <el-select v-model="search.work_uid" placeholder="检验员" filterable clearable>
                        <el-option v-for="item in adminList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                    </el-select>
                </div>
            </div>
        </el-header>
        <el-header style="height:auto">
            <div class="left-panel"></div>
            <div class="right-panel">
                <div class="right-panel-search" style="flex-wrap:wrap;">
                    <el-input v-model="search.search_keyword"  class="input-with-search" style="margin:5px;width: 300px" @keyup.enter="upsearch">
                        <template #prepend>
                            <el-select v-model="search.search_field" filterable clearable placeholder="请选择" style="width: 110px">
                                <el-option label="布卷条码" value="roll_code"/>
                                <el-option label="Color" value="color"/>
                                <el-option label="染色方" value="dye_factory_name"/>
                                <el-option label="加工方" value="process_factory_name"/>
                                <el-option label="批号" value="batch_num"/>
                            </el-select>
                        </template>
                    </el-input>
                    <sc-auto-complete style="margin:5px;width: 180px" v-model="search.goods_name" :api="$API.basic.goods.list" :params-key="'name'" :value-key="'name'" placeholder="品名" @select="getGoods"/>
                    <sc-auto-complete style="margin:5px;width: 180px" v-model="search.flower" :api="$API.basic.allFlower" :additionalParams="{type: 2}" :params-key="'flower'" :rows-key="'rows'" :value-key="'flower'" placeholder="花型" @select="getFlower"/>
                    <sc-auto-complete style="margin:5px;width: 180px" v-model="search.goods_code" :api="$API.basic.goods.list" :params-key="'code'" :rows-key="'rows'" :value-key="'code'" placeholder="货号" @select="getGoodsCode"/>
                    <el-input style="margin:5px;width: 80px" v-model="search.gram_weight[0]" placeholder="克重" clearable @keyup.enter="upsearch"></el-input>
                    <span> - </span>
                    <el-input style="margin:5px;width: 80px" v-model="search.gram_weight[1]" placeholder="克重" clearable @keyup.enter="upsearch"></el-input>
                    <!-- <el-input style="margin:5px" v-model="search.apply_name" placeholder="供应商" clearable @keyup.enter="upsearch"></el-input> -->
                    <el-select style="margin:5px" v-model="search.ware_id" placeholder="仓库" filterable clearable>
                        <el-option v-for="item in wareList" :key="item.id" :label="item.ware_name" :value="item.id"></el-option>
                    </el-select>
                    <el-date-picker v-model="search.date" :value-format="'YYYY-MM-DD'" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="margin:5px;width: 220px" />
                    <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
                    <el-button type="primary" icon="el-icon-refresh" @click="refresh"></el-button>
                </div>
            </div>
        </el-header>
        <el-main class="nopadding">
            <scTable ref="table" :apiObj="apiObj" row-key="id" @selection-change="selectionChange" border @setExtend="setExtend" :params="search" tableName="inwareTable" :column="inwareColumn">
                <el-table-column fixed type="selection" width="50" align="center"></el-table-column>
                <!-- <el-table-column fixed type="index" width="50" align="center"></el-table-column> -->
                <template #index="scope">
                    {{ scope.$index + 1 }}
                </template>
                <template #operation="scope">
                    <el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
                        <template #reference>
                            <el-button type="danger" size="small" v-auth="'summary.delete'" v-if="scope.row.is_old == 1">删除</el-button>
                        </template>
                    </el-popconfirm>
                </template>
                <!-- <el-table-column label="布卷条码" prop="roll_code" align="center" width="150"></el-table-column>
                <el-table-column label="品名" prop="goods_name" align="center" width="130"></el-table-column>
                <el-table-column label="货号" prop="goods_code" align="center" width="130"></el-table-column>
                <el-table-column label="花型" prop="flower" align="center" width="120"></el-table-column>
                <el-table-column label="颜色" prop="color" align="center" width="120"></el-table-column>
                <el-table-column label="Color" prop="colorName.name" align="center" width="120"></el-table-column>
                <el-table-column label="来数" prop="come" align="center" width="100"></el-table-column>
                <el-table-column label="米数" prop="meter" align="center" width="100"></el-table-column>
                <el-table-column label="码数" prop="code_number" align="center" width="100"></el-table-column>
                <el-table-column label="净重" prop="net_weight" align="center" width="100"></el-table-column>
                <el-table-column label="克重" prop="gram_weight" align="center" width="100"></el-table-column>
                <el-table-column label="仓库" prop="ware.ware_name" align="center" width="110"></el-table-column>
                <el-table-column label="折码" prop="folding.name" align="center" width="100"></el-table-column>
                <el-table-column label="次品种类" prop="rejectCate.name" align="center" width="100"></el-table-column>
                <el-table-column label="检验员" prop="work_uids_name" align="center" width="120"></el-table-column>
                <el-table-column label="供应商" prop="apply_name" align="center" width="100"></el-table-column>
                <el-table-column label="染色方" prop="dye_factory_name" align="center" width="100"></el-table-column>
                <el-table-column label="加工方" prop="process_factory_name" align="center" width="100"></el-table-column>
                <el-table-column label="批号" prop="batch_num" align="center" width="150"></el-table-column>
                <el-table-column label="成本价" prop="base_price" align="center" width="100"></el-table-column>
                <el-table-column label="指导价" prop="price" align="center" width="100"></el-table-column> -->
                <!-- <el-table-column label="操作" fixed="right" align="center" width="100">
                    <template #default="scope">
                        <el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
                            <template #reference>
                                <el-button type="danger" size="small" v-auth="'dyehouse.delete'" v-if="scope.row.status != 1">删除</el-button>
                            </template>
                        </el-popconfirm>
                    </template>
                </el-table-column> -->
            </scTable>
        </el-main>
        <select-house v-if="dialog.house" ref="houseDialog" @success="houseBack" @closed="dialog.house = false" :query="query"></select-house><!-- 入库记录 -->
    </el-container>
</template>

<script>
import SelectHouse from '@/views/business/selectHouse.vue';
import config from '@/config'
export default {
    name: '在库明细',
    components: {
        SelectHouse
    },
    data() {
        return {
            dialog: {
                house: false
            },
            apiObj: this.$API.ware.ware.summary.list,
            selection: [],
            search: {
                // date: [this.moment().subtract(7, 'days').format('YYYY-MM-DD'), this.moment().format('YYYY-MM-DD')],
                date: null,
                ware_id: null,
                search_keyword: "",
                search_field: "roll_code",
                goods_name: null,
                flower: null,
                apply_name: null,
                gram_weight: [],
                is_send: 0,
                work_uid: "",
                goods_code: "",
            },
            total_stock: {
                meter_sum: 0,
                count: 0,
                code_number_sum: 0,
                net_weight_sum: 0,
            },
            wareList: [],
            adminList: [],
			base: config.API_URL,
			importObj: this.$API.ware.ware.summary.import,
            inwareColumn: [
                {label: "序号", prop: "index", align: "center", width: "50", type: "index"},
                {label: "布卷条码", prop: "roll_code", align: "center", width: "120"},
                {label: "品名", prop: "goods_name", align: "center"},
                {label: "货号", prop: "goods_code", align: "center"},
                {label: "花型", prop: "flower", align: "center", width: "150"},
                {label: "颜色", prop: "color", align: "center", width: "120"},
                {label: "Color", prop: "color_en", align: "center"},
                {label: "来数", prop: "come", align: "center"},
                {label: "米数", prop: "meter", align: "center"},
                {label: "码数", prop: "code_number", align: "center"},
                {label: "净重", prop: "net_weight", align: "center"},
                {label: "克重", prop: "gram_weight", align: "center"},
                {label: "仓库", prop: "ware.ware_name", align: "center"},
                {label: "折码", prop: "folding", align: "center"},
                {label: "次品种类", prop: "reject_cate", align: "center"},
                {label: "检验员", prop: "work_uids_name", align: "center"},
                {label: "供应商", prop: "apply_name", align: "center"},
                {label: "染色方", prop: "dye_factory_name", align: "center"},
                {label: "加工方", prop: "process_factory_name", align: "center"},
                {label: "批号", prop: "batch_num", align: "center", width: "150"},
                {label: "成本价", prop: "base_price", align: "center",columbAuth: "inware.base_price"},
                {label: "指导价", prop: "price", align: "center",columbAuth: "inware.price"},
                {label: "操作", prop: "operation", width: "100",fixed: "right"},
            ],
        }
    },
    mounted() {
		this.getWare();
		this.getAdmin();
    },
    methods: {
        importSuccess(){
            this.$refs.table.refresh()
        },
        setExtend(data){
            this.total_stock = data
        },
        upsearch(){
            this.$refs.table.upData(this.search)
        },
        refresh() {
            for (const key in this.search) {
                this.search[key] = null;
            }
            this.search.gram_weight = []
            this.search.is_send = 0
            this.$refs.table.upData(this.search)
        },
        // 仓库
		async getWare() {
			var res = await this.$API.basic.ware.all.get({has_cheng: 1});
			this.wareList = res.data
		},
        // 管理员
		async getAdmin() {
			var res = await this.$API.system.admin.all.get();
			this.adminList = res.data
		},
        selectionChange(selection) {
			this.selection = selection;
		},
        //删除
        async table_del(row) {
            var reqData = { id: row.id,old_delete: 1 }
            var res = await this.$API.business.inspect.execute.delete.post(reqData);
            if (res.code == 1) {
                this.$refs.table.refresh()
                this.$message.success("删除成功")
            } else {
                this.$alert(res.message, "提示", { type: 'error' })
            }
        },

        //批量删除
        async batch_del() {
            var delete_ids = [];
            this.selection.forEach((item) => {
                delete_ids.push(item.id)
            })

            this.$confirm(`确定删除选中的 ${this.selection.length} 项吗？`, '提示', {
                type: 'warning'
            }).then(async() => {
                var reqData = { id: delete_ids,old_delete: 1 }
                var res = await this.$API.business.inspect.execute.delete.post(reqData);
                if (res.code == 1) {
                    this.$refs.table.refresh()
                    this.$message.success("删除成功")
                } else {
                    this.$alert(res.message, "提示", { type: 'error' })
                }
            }).catch(() => {

            })
        },
        getGoods(data){
            this.search.goods_name = data.name
            this.upsearch()
        },
        getGoodsCode(data){
            this.search.goods_code = data.code
            this.upsearch()
        },
        getApply(data){
            this.search.apply_name = data.apply_name
            this.upsearch()
        },
        getFlower(data){
            this.search.flower = data.flower
            this.upsearch()
        }
    }
}
</script>

<style lang="scss" scoped>
table{
    text-align: center ;
}
</style>
